package cn.myjerry.iter;

/**
 * 目标：理解迭代器的原理
 * 迭代器：遍历使用
 * 
 * @author Jerry
 *
 */

public class SxtSimpleList {
	private String[] element = {"a","b","c","d","e"};
	private int size = element.length;
	private int coursor = -1;
	
	public int size() {
		return size;
	}
	
	public boolean hashNext() {
		return coursor+1<size;
	}
	
	public String next() {
		return element[++coursor];
	}
	
	public void remove() {
		System.arraycopy(element, coursor, element, coursor+1, size-(coursor+1));
		size--;
		coursor--;
	}
	
	public static void main(String[] args) {
		SxtSimpleList list = new SxtSimpleList();
		if(list.hashNext()){
			System.out.println(list.next());
		}
		if(list.hashNext()){
			System.out.println(list.next());
		}
		if(list.hashNext()){
			System.out.println(list.next());
		}
		if(list.hashNext()){
			System.out.println(list.next());
		}
		if(list.hashNext()){
			System.out.println(list.next());
		}
		
		System.out.println(list.size());
		
	}
}
